#include "Material.hpp"
#include "../../Graphics/Graphics.hpp"
#include <Utility/Tools.hpp>
#include <Resource/Texture/Texture2DIOObject.hpp>


namespace zzz{

Material::Material()
:diffuse_(0.8f,0.8f,0.8f,1.0f),
ambient_(0.7f,0.7f,0.7f,1.0f),
specular_(1.0f,1.0f,1.0f,1.0f),
emission_(0.0f,0.0f,0.0f,1.0f),
shininess_(100.0f)
{}

Material::~Material()
{}

void Material::ApplyMaterial()
{
  if (HasFlag(MAT_AMB))
    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,ambient_.Data());
  if (HasFlag(MAT_DIF))
    glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,diffuse_.Data());
  if (HasFlag(MAT_SPE))
  {
    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,specular_.Data());
    glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,shininess_);
  }
  if (HasFlag(MAT_EMI))
    glMaterialfv(GL_FRONT_AND_BACK,GL_EMISSION,emission_.Data());
}

void Material::BindDiffuseTexture(GLenum bindto /*= GL_TEXTURE0*/)
{
  if (HasFlag(MAT_DIFTEX))
    diffuseTex_.Bind(bindto);
}

void Material::UnbindDiffuseTexture()
{
  if (HasFlag(MAT_DIFTEX))
    diffuseTex_.Unbind();
}

void Material::BindAmbientTexture(GLenum bindto /*= GL_TEXTURE0*/)
{
  if (HasFlag(MAT_AMBTEX))
    ambientTex_.Bind(bindto);
}

void Material::UnbindAmbientTexture()
{
  if (HasFlag(MAT_AMBTEX))
    ambientTex_.Unbind();
}


}

